const jwt = require('jsonwebtoken');
const {SECRET_KEY} = require('./constants');

exports.createToken = (data, expiresIn='7d')=>{
    return jwt.sign(data, SECRET_KEY, {expiresIn})
}

exports.verifyToken = (token)=>{
    return new Promise((resolve,reject)=>{
        jwt.verify(token, SECRET_KEY, (err, data)=>{
            if(err){
                reject(err);
            }else{
                console.log('data: ', data);
                resolve(data);
            }
        })
    })
}
